import { useReducer } from "react";
const getDefaultCity=()=>{
    let defaultCity ="武汉";
    if(localStorage.getItem("city")){
        defaultCity =localStorage.getItem("city")
    }
    return defaultCity
}
const useMyReducer =()=>{
    const initState ={
        city:getDefaultCity()
    }
    const reducer =(state,action)=>{
       
        if(action.type==="changeCity"){
            localStorage.setItem("city",action.value)
            return {
                city:action.value
            }
        }
        return initState;
    }
    
const [state,dispatch] =useReducer(reducer,initState);
return [state,dispatch];
}

export default useMyReducer;